#!/usr/bin/python
# -*- coding: utf-8 -*-
# File: constants.py
# Author: Tomás Vírseda
# License: GPL v3
# Description:  globals

import os
from os.path import abspath, split
#from ConfigParser import ConfigParser
import gettext
import sys
#import gettext
import gtk


VAZAAR_VERSION = '0.4'
VAZAAR_NAME = 'Vazaar'
VAZAAR_COPYRIGHT = 'Copyright (c) 2004-2009 Tomás Vírseda García'
VAZAAR_WEBSITE = 'https://launchpad.net/vazaar'
VAZAAR_WEBSITE_LABEL = 'The Vazaar Project'
VAZAAR_AUTHOR = 'Tomás Vírseda <kaskaras@gmail.com>'
VAZAAR_LICENSE = """The code is licensed under the terms of the GPL v3 so you're free to grab, extend, improve and fork the code as you want"""
VAZAAR_MAINTAINER = VAZAAR_AUTHOR
VAZAAR_AUTHORS = [VAZAAR_AUTHOR] #+ [ 'Your Name <your@mail>', ]
VAZAAR_SHORT_DESCRIPTION = 'A Personal Information Manager'


DIR='po'
gettext.bindtextdomain(VAZAAR_NAME, DIR)
gettext.textdomain(VAZAAR_NAME)
gtk.glade.bindtextdomain(VAZAAR_NAME, DIR)
gtk.glade.textdomain(VAZAAR_NAME)
_ = gettext.gettext




# install dirs
#p = abspath(sys.modules[__name__].__file__ + "/..")
#global develop

p = abspath(sys.modules[__name__].__file__ + "/..")
if '/usr/' in p:
    ROOT_DIR = '/usr/share/vazaar'
else:
    ROOT_DIR = str(split(p)[0])

#ROOT_DIR = '/usr/share/vazaar'
DATA_DIR = ROOT_DIR + "/data"
DOC_DIR = ROOT_DIR + "/doc"
RESOURCES_DIR = ROOT_DIR + "/data"
BACKUP_DIR = RESOURCES_DIR + "/backups"
IMAGES_DIR = RESOURCES_DIR + "/icons"
EMOTES_DIR = IMAGES_DIR + "/emotes"
GUI_DIR = RESOURCES_DIR + "/glade"
GETTEXT_DIR = RESOURCES_DIR + "/po"
PLUGIN_LOCAL_DIR = RESOURCES_DIR + "/plugins"
WIDGET_LOCAL_DIR = RESOURCES_DIR + "/widgets"
BIN_DIR = ROOT_DIR + "/bin"
PLUGIN_DIR = BIN_DIR + "/plugins"
WIDGET_DIR = BIN_DIR + "/ui/widgets"

# user dirs
USER_DIR = os.environ['HOME']
VAZAAR_USER_DIR = USER_DIR + '/.vazaar'
METADATA_DIR = VAZAAR_USER_DIR + "/.metadata"
VAZAAR_USER_RESOURCES_DIR = VAZAAR_USER_DIR + "/data"
VAZAAR_USER_IMAGES_DIR = VAZAAR_USER_RESOURCES_DIR +"/icons"
VAZAAR_USER_EMOTES_DIR = VAZAAR_USER_IMAGES_DIR + "/emotes"
VAZAAR_USER_PLUGIN_LOCAL_DIR = VAZAAR_USER_RESOURCES_DIR + "/plugins"
VAZAAR_USER_WIDGET_LOCAL_DIR = VAZAAR_USER_RESOURCES_DIR + "/widgets"
VAZAAR_USER_TMP_DIR = VAZAAR_USER_DIR + "/tmp"
VAZAAR_USER_THUMBS_DIR = VAZAAR_USER_DIR + "/.thumbs"

# Configuration files and directories
GLOBAL_CONFIG_DIR = USER_DIR + '/.config/vazaar/'
GLOBAL_CONFIG_FILE = GLOBAL_CONFIG_DIR + 'vazaar.conf'
VAZAAR_CONFIG_DIR = VAZAAR_USER_DIR
VAZAAR_CONFIG_FILE = VAZAAR_CONFIG_DIR + '/vazaar.conf'

#log.info("Metadata: %s" % METADATA_DIR)
#log.info("Stuff: %s" % ROOT_DIR)

# Default files
"""
TAG_COMPLETION_FILE  = os.path.join(RESOURCES_DIR, "tags.csv")
WHITELIST_EXTENSION_FILE = os.path.join(RESOURCES_DIR, "extensions.csv")

EXTENSIONS = {}
try:
    f = open(os.path.join(RESOURCES_DIR, WHITELIST_EXTENSION_FILE))
    for line in f.readlines():
        name, filetype, description = line.split(',')
        EXTENSIONS[name] = (filetype, description)
    f.close()
except Exception, error:
    print error #log.error("%s: %s" % (__name__, e))
"""

# Options defaults
AUTOSAVE_TIMEOUT = 1000*60*5 # 5min
SHOW_EXT_ON_STARTUP = False

AUTHORS = """
Tomás Vírseda <kaskaras@gmail.com>
"""

TRANSLATORS = """
Tomás Vírseda <kaskaras@gmail.com>
"""

HELP_MESSAGE = _("""Modo de empleo: vazaar [OPCIÓN]... """)


VAZAAR_METADATA_DIR = VAZAAR_USER_DIR + "/.metadata"
VAZAAR_USER_RESOURCES_DIR = VAZAAR_USER_DIR + "/data"
VAZAAR_USER_IMAGES_DIR = VAZAAR_USER_RESOURCES_DIR +"/icons"
VAZAAR_USER_EMOTES_DIR = VAZAAR_USER_IMAGES_DIR + "/emotes"
VAZAAR_USER_TMP_DIR = VAZAAR_USER_DIR + "/tmp"
#USER_PLUGIN_DIR = USER_RESOURCES_DIR + "/plugins"

# List of schemes
# RFC 1738: <scheme>://<user>:<password>@<host>:<port>/<url-path>;<params>?<query>#<fragment>

SCHEMES_WHITELIST = {
'aaa': 'Diameter Protocol [RFC3588]',
'aaas': 'Diameter Protocol with Secure Transport [RFC3588]',
'acap': 'application configuration access protocol [RFC2244]',
'cap': 'Calendar Access Protocol [RFC4324]',
'cid': 'content identifier [RFC2392]',
'crid': 'TV-Anytime Content Reference Identifier [RFC4078]',
'data': 'data [RFC2397]',
'dav': 'dav [RFC4918]',
'dict': 'dictionary service protocol [RFC2229]',
'dns': 'Domain Name System [RFC4501]',
'fax': 'fax (historical, see [RFC3966]) [RFC2806]',
'file': 'Host-specific file names [RFC1738]',
'ftp': 'File Transfer Protocol [RFC1738]',
'go': 'go [RFC3368]',
'gopher': 'The Gopher Protocol [RFC4266]',
'h323': 'H.323 [RFC3508]',
'http': 'Hypertext Transfer Protocol [RFC2616]',
'https': 'Hypertext Transfer Protocol Secure [RFC2818]',
'iax': 'Inter-Asterisk eXchange Version 2 [RFC-guy-iax-05.txt]',
'icap': 'Internet Content Adaptation Protocol [RFC3507]',
'im': 'Instant Messaging [RFC3860]',
'imap': 'internet message access protocol [RFC5092]',
'info': 'Information Assets with Identifiers in Public Namespaces [RFC4452]',
'ipp': 'Internet Printing Protocol [RFC3510]',
'iris': 'Internet Registry Information Service [RFC3981]',
'iris.beep': 'iris.beep [RFC3983]',
'iris.xpc': 'iris.xpc [RFC4992]',
'iris.xpcs': 'iris.xpcs [RFC4992]',
'iris.lwz': 'iris.lwz [RFC4993]',
'ldap': 'Lightweight Directory Access Protocol [RFC4516]',
'mailto': 'Electronic mail address [RFC2368]',
'mid': 'message identifier [RFC2392]',
'modem': 'modem (historical, see [RFC3966]) [RFC2806]',
'msrp': 'Message Session Relay Protocol [RFC4975]',
'msrps': 'Message Session Relay Protocol Secure [RFC4975]',
'mtqp': 'Message Tracking Query Protocol [RFC3887]',
'mupdate': 'Mailbox Update (MUPDATE) Protocol [RFC3656]',
'news': 'USENET news [RFC-ellermann-news-nntp-uri-11.txt]',
'nfs': 'network file system protocol [RFC2224]',
'nntp': 'USENET news using NNTP access [RFC-ellermann-news-nntp-uri-11.txt]',
'opaquelocktoken': 'opaquelocktokent [RFC4918]',
'pop': 'Post Office Protocol v3 [RFC2384]',
'pres': 'Presence [RFC3859]',
'rtsp': 'real time streaming protocol [RFC2326]',
'service': 'service location [RFC2609]',
'shttp': 'Secure Hypertext Transfer Protocol [RFC2660]',
'sieve': 'ManageSieve Protocol [RFC-ietf-sieve-managesieve-09.txt]',
'sip': 'session initiation protocol [RFC3261]',
'sips': 'secure session initiation protocol [RFC3261]',
'snmp': 'Simple Network Management Protocol [RFC4088]',
'soap.beep': 'soap.beep [RFC4227]',
'soap.beeps': 'soap.beeps [RFC4227]',
'tag': 'tag [RFC4151]',
'tel': 'telephone [RFC3966]',
'telnet': 'Reference to interactive sessions [RFC4248]',
'tftp': 'Trivial File Transfer Protocol [RFC3617]',
'thismessage': 'multipart/related relative reference resolution [RFC2557]',
'tip': 'Transaction Internet Protocol [RFC2371]',
'tv': 'TV Broadcasts [RFC2838]',
'urn': 'Uniform Resource Names (click for registry) [RFC2141]',
#'vazaar': 'Vazaar Resource',
'vemmi': 'versatile multimedia interface [RFC2122]',
'xmlrpc.beep': 'xmlrpc.beep [RFC3529]',
'xmlrpc.beeps': 'xmlrpc.beeps [RFC3529]',
'xmpp': 'Extensible Messaging and Presence Protocol [RFC5122]',
'z39.50r': 'Z39.50 Retrieval [RFC2056]',
'z39.50s': 'Z39.50 Session [RFC2056]'
}

try:
    if not os.path.isdir(VAZAAR_METADATA_DIR):
        #print "Creating metadata dir %s" % METADATA_DIR
        os.makedirs(VAZAAR_METADATA_DIR)
except Exception:
    pass

try:
    if not os.path.isdir(VAZAAR_USER_RESOURCES_DIR):
        os.makedirs(VAZAAR_METADATA_DIR)
except Exception:
    pass

try:
    if not os.path.isdir(VAZAAR_USER_IMAGES_DIR):
        os.makedirs(VAZAAR_USER_IMAGES_DIR)
except Exception:
    pass

try:
    if not os.path.isdir(VAZAAR_USER_EMOTES_DIR):
        os.makedirs(VAZAAR_USER_EMOTES_DIR)
except Exception:
    pass

try:
    if not os.path.isdir(VAZAAR_USER_TMP_DIR):
        os.makedirs(VAZAAR_USER_TMP_DIR)
except Exception:
    pass

try:
    if not os.path.isdir(VAZAAR_USER_THUMBS_DIR):
        os.makedirs(VAZAAR_USER_THUMBS_DIR)
except Exception:
    pass

"""
Disabled feature:

if not os.path.isdir(USER_PLUGIN_DIR):
    os.makedirs(USER_PLUGIN_DIR)
"""
